package com.manage.controller; /**
 * @author 汤奇
 * @version V1.0
 * @Project BookPro
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/27 15:27
 */

import com.manage.dao.ProfileDaoImpl;
import com.manage.pojo.Profile;
import com.manage.service.ProfileService;
import com.manage.service.ProfileServiceImpl;
import com.manage.util.StrUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "DetailServlet", value = "/detail")
public class DetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        //1.获取前端传来的数据
        String id = request.getParameter("profileId");

        //2.判断数据是否为空
        if (!StrUtils.empty(id)){
            //为空,跳转到登录页
            response.sendRedirect(request.getContextPath()+"/list.jsp");
            return;
        }
        //3.调用service
        ProfileService service = new ProfileServiceImpl(new ProfileDaoImpl());
        Profile Profile = service.findById(Integer.parseInt(id));

        //4.将信息保存到session,跳转
        request.getSession().setAttribute("Profile",Profile);
        response.sendRedirect(request.getContextPath()+"/detail.jsp");

    }
}
